﻿using FitnessCenter.Common.Constants;
using FitnessCenter.DataAccessLayer.DataModels;
using FitnessCenter.DataAccessLayer.Repositories.Interfaces;
using FitnessCenter.WpfApp.Events;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.PubSubEvents;
using System.Collections.ObjectModel;
using System.Windows.Input;

namespace FitnessCenter.WpfApp.ViewModels
{
    public class ActivityViewModel : BaseViewModel
    {
        private readonly IActivityRepository _activityRepository;
        private readonly IPersonRepository _personRepository;

        #region Properties

        #region Labels

        private string _returnLabel;
        public string ReturnLabel
        {
            get { return _returnLabel; }
            set
            {
                if (_returnLabel != value)
                {
                    _returnLabel = value;
                    OnPropertyChanged();
                }
            }
        }

        private string _saveLabel;
        public string SaveLabel
        {
            get { return _saveLabel; }
            set
            {
                if (_saveLabel != value)
                {
                    _saveLabel = value;
                    OnPropertyChanged();
                }
            }
        }

        private string _cancelLabel;
        public string CancelLabel
        {
            get { return _cancelLabel; }
            set
            {
                if (_cancelLabel != value)
                {
                    _cancelLabel = value;
                    OnPropertyChanged();
                }
            }
        }

        private string _newLabel;
        public string NewLabel
        {
            get { return _newLabel; }
            set
            {
                if (_newLabel != value)
                {
                    _newLabel = value;
                    OnPropertyChanged();
                }
            }
        }

        private string _editLabel;
        public string EditLabel
        {
            get { return _editLabel; }
            set
            {
                if (_editLabel != value)
                {
                    _editLabel = value;
                    OnPropertyChanged();
                }
            }
        }

        private string _deleteLabel;
        public string DeleteLabel
        {
            get { return _deleteLabel; }
            set
            {
                if (_deleteLabel != value)
                {
                    _deleteLabel = value;
                    OnPropertyChanged();
                }
            }
        }

        private string _activityNameLabel;
        public string ActivityNameLabel
        {
            get { return _activityNameLabel; }
            set
            {
                if (_activityNameLabel != value)
                {
                    _activityNameLabel = value;
                    OnPropertyChanged();
                }
            }
        }

        private string _coachLabel;
        public string CoachLabel
        {
            get { return _coachLabel; }
            set
            {
                if (_coachLabel != value)
                {
                    _coachLabel = value;
                    OnPropertyChanged();
                }
            }
        }
        #endregion

        private ObservableCollection<Person> _coaches;
        public ObservableCollection<Person> Coaches
        {
            get { return _coaches; }
            set
            {
                if (_coaches != value)
                {
                    _coaches = value;
                    OnPropertyChanged();
                }
            }
        }

        private Person _selectedCoach;
        public Person SelectedCoach
        {
            get { return _selectedCoach; }
            set
            {
                if (_selectedCoach != value)
                {
                    _selectedCoach = value;
                    OnPropertyChanged();
                }
            }
        }

        private string _activityName;
        public string ActivityName
        {
            get { return _activityName; }
            set
            {
                if (_activityName != value)
                {
                    _activityName = value;
                    OnPropertyChanged();
                }
            }
        }
        #endregion

        #region Commands

        public ICommand ReturnCommand { get { return new DelegateCommand(OnReturn); } }
        public ICommand SaveCommand { get { return new DelegateCommand(OnSave); } }
        public ICommand CancelCommand { get { return new DelegateCommand(OnCancel); }}
        public ICommand NewCommand { get { return new DelegateCommand(OnNew); } }
        public ICommand EditCommand { get { return new DelegateCommand(OnEdit); }}
        public ICommand DeleteCommand { get { return new DelegateCommand(OnDelete); }}
        #endregion

        public ActivityViewModel
            (
                IEventAggregator eventAggregator,
                IActivityRepository activityRepository,
                IPersonRepository personRepository
            ) : base(eventAggregator)
        {
            _activityRepository = activityRepository;
            _personRepository = personRepository;

            Load();
        }

        #region Methods

        private void Load()
        {
            SetLabels();
        }

        private void SetLabels()
        {
            ReturnLabel = Phrases.ReturnToDashboard;
        }
        #endregion

        #region Command handlers

        private void OnReturn()
        {
            EventAggregator.GetEvent<SelectModuleEvent>().Publish(ModuleNames.DashboardModule);
        }

        private void OnSave()
        {
            
        }

        private void OnCancel()
        {
            
        }

        private void OnNew()
        {
            
        }

        private void OnEdit()
        {
            
        }

        private void OnDelete()
        {
            
        }
        #endregion
    }
}
